package cluster_node.scheduler.service;

import cluster_node.scheduler.type_config.TypeDeviceUploadHelper;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TypeHandlerService {
    private static TypeHandlerService instance = null;
    public synchronized static TypeHandlerService getInstance() {
        if (instance == null) {
            instance = new TypeHandlerService();
        }
        return instance;
    }

    private Map<String, TypeDeviceUploadHelper> map;

    private TypeHandlerService() {
        this.map = new HashMap<>();

        init();
    }

    private void init() {
        loadLocalHandler();
        loadDynamicHandler();
    }

    private void loadLocalHandler() {
        Map<Integer, List<Integer>> waterMeterResourceMap = new HashMap<Integer, List<Integer>>() {
            {
                put(3300, Arrays.asList(5700));
            }
        };
        TypeDeviceUploadHelper waterMeterHelper = new TypeDeviceUploadHelper(waterMeterResourceMap);
        map.put("waterMeter", waterMeterHelper);

        Map<Integer, List<Integer>> temperatureResourceMap = new HashMap<Integer, List<Integer>>() {
            {
                put(3303, Arrays.asList(5700));
            }
        };
        TypeDeviceUploadHelper temperatureHelper = new TypeDeviceUploadHelper(temperatureResourceMap);
        map.put("Model 500", temperatureHelper);

        Map<Integer, List<Integer>> model100 = new HashMap<Integer, List<Integer>>() {
            {
                put(3303, Arrays.asList(5700));
                put(3300, Arrays.asList(5700));
            }
        };
        TypeDeviceUploadHelper model100Helper = new TypeDeviceUploadHelper(model100);
        map.put("Model-100", model100Helper);

    }

    private void loadDynamicHandler() {

    }

    public TypeDeviceUploadHelper getHelper(String type) {
        if (map.containsKey(type)) {
            return map.get(type);
        }
        // todo: default helper
        return null;
    }
}
